{% extends "staff/base.html" %}

{% block title %} Job {{ job.id }} - {{ current_course.display_name_with_semester }}{% endblock %}

{% block main %}
<section class="content-header">
    <h1>
        {{ current_course.display_name_with_semester }} Jobs
        <small>{{ current_course.offering }}</small>
    </h1>
    <ol class="breadcrumb">
        <li><a href="{{ url_for(".course", cid=current_course.id) }}">
            <i class="fa fa-university"></i> {{ current_course.offering }}
        </a></li>
        <li><a href="{{ url_for(".course_jobs", cid=current_course.id) }}">
            <i class="fa fa-list"></i>Jobs
        </a></li>
        <li class="active"><a href="{{ url_for('.course_job', cid=current_course.id, job_id=job.id) }}">
            <i class="fa fa-file-text"></i>Job {{ job.id }}</a>
        </li>
    </ol>
</section>
<section class="content">
  {% include 'alerts.html' %}
  <div class="row">
    <div class="col-md-12">
      <div class="box box-solid">
        <div class="box-header with-border">
          <i class="fa fa-file-text"></i>
          <h3 class="box-title">Job {{ job.id }}</h3>
        </div>
        <!-- /.box-header -->
        <div class="box-body">
          <dl class="dl-horizontal">
            <dt>Description</dt>
            <dd>{{ job.description }}</dd>
            <dt>User</dt>
            <dd>{{ job.user.email }}</dd>
            <dt>Status</dt>
            {% if job.status == 'queued' %}
              <dd>Queued (Refreshing...)</dd>
            {% elif job.status == 'running' %}
              <dd>Running (Refreshing...)</dd>
            {% elif job.status == 'finished' %}
              <dd>{{ 'Failed' if job.failed else 'Finished' }}</dd>
            {% endif %}
            <dt>Result</dt>
            {% if not job.result %}
              <dd> &mdash; </dd>
            {% elif job.result_kind == "link" %}
              <dd> <a href="{{ job.result }}" target="_blank">Go to {{   job.result  | truncate(70, True) }} </a>
              </dd> <br/>
            {% elif job.result_kind == "string" %}
              <dd> {{ job.result | truncate(255) }} </dd> <br/>
            {% elif job.result_kind == "html" %}
             <dd> {{ job.result | safe }} </dd> <br/>
            {% endif %}
            {% if job.log %}
              <dt>Log</dt>
              <dd><pre>{{ job.log }}</pre></dd>
            {% endif %}
          </dl>
        </div>
        <!-- /.box-body -->
      </div>
      <!-- /.box -->
    </div>
  </div>
</section>
{% endblock %}

{% block page_js %}
<script>
  {% if job.status == 'queued' or  job.status == 'running' %}
  // Reload the page every 4.5 seconds
  setTimeout(function(){
     window.location.reload();
  }, 4500);
  {% endif %}
</script>
{% endblock %}
